//
//  NetworkHelper.m
//  跨界收
//
//  Created by emingiMac on 2018/11/14.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "NetworkHelper.h"
#import "NetworkManager.h"

@implementation NetworkHelper

+ (NSString *)domainURL {
    return @"http://domain.kuajieshou.com";
}

+ (NSString *)baseURL {
    return [Tool getLocalDataValue:@"serverUrl"];
}

+ (NSString *)append:(NSString *)string {
    return [[self baseURL] stringByAppendingString:string];
}

#pragma mark -- user / account
+ (NSString *)accountCodeURL {
    return [self append:@"/Api/Sms/send"];
}

+ (NSString *)registerURL {
    return [self append:@"/Api/User/shopRegister"];
}

+ (NSString *)loginURL {
    return [self append:@"/Api/Login/common"];
}

+ (NSString *)userInfoURL {
    return [self append:@"/Api/User/getUserInfo"];
}



+ (BOOL)isNetworkAPIExist {
    return [Tool getLocalDataValue:kBaseURLKey] != nil;
}

+ (void)getNetworkAPIWithComplete:(void (^)(BOOL result))result {
    [NetworkManager post:[self domainURL] parameters:nil success:^(id object) {
        if (object) {
            NSString *baseURL = object[@"data"][@"domain"]; NSLog(@"baseURL: %@", baseURL);
            if ([Tool isBlankString:baseURL]) {
                result(NO);
            } else {
                [Tool setLocalDataValue:baseURL key:kBaseURLKey];
                result(YES);
            }
        } else {
            result(NO);
        }        
    } failure:^(NSError *error) {
        result(NO);
    }];
}

@end
